<template>
    <div class="container-userauth">
        <a-modal width="1100px" :visible="visible" title="审核详情" @cancel="closeModal" class="yuan-modal userauth-modal"
            :dialog-style="{ top: '20px' }">
            <a-form-model layout="inline" class="yuan-form" :label-col="{ style: { width: '120px' } }"
                :wrapper-col="{ style: { width: 'calc(100% - 130px)' } }" ref="form">
                <div class="form-title">人物信息</div>
                <div class="form-panel yuan-form-col3">
                    <a-form-model-item class="yuan-form-item" label="角色权限" prop="phone">
                        <span class="yuan-form-input">{{detailInfo.roleName}}</span>
                    </a-form-model-item>
                    <a-form-model-item class="yuan-form-item" label="角色身份" prop="phone">
                        <span class="yuan-form-input">{{detailInfo.userType}}</span>
                    </a-form-model-item>
                    <a-form-model-item class="yuan-form-item" label="手机号" prop="phone">
                        <span class="yuan-form-input">{{detailInfo.phone}}</span>
                    </a-form-model-item>
                    <div class="clear-both"></div>

                    <!----------- 个人 --------->
                    <template v-if="detailInfo.userType==='个人'">
                        <a-form-model-item class="yuan-form-item" label="姓名" prop="userName">
                            <span class="yuan-form-input">{{detailInfo.name}}</span>
                        </a-form-model-item>
                        <a-form-model-item class="yuan-form-item" label="性别">
                            <span class="yuan-form-input">{{detailInfo.gender}}</span>
                        </a-form-model-item>
                        <div class="clear-both"></div>
                        <a-form-model-item class="yuan-form-item" label="所在企业" prop="phone">
                            <span class="yuan-form-input">{{detailInfo.placeEnterprise}}</span>
                        </a-form-model-item>
                        <a-form-model-item class="yuan-form-item" label="身份证号" prop="phone">
                            <span class="yuan-form-input">{{detailInfo.identityCard}}</span>
                        </a-form-model-item>
                        <div class="clear-both"></div>
                        <a-form-model-item label="上传头像" class="yuan-form-row">
                            <div class="imagePreBox">
                                <img class="imagePreview" :src="detailInfo.headPortrait" alt=""
                                    @click="imgClick(detailInfo.headPortrait)">
                            </div>

                        </a-form-model-item>

                        <div class="clear-both" style="margin-top:10px"></div>
                        <a-form-model-item class="yuan-form-row" label="简介" prop="phone">
                            <span class="yuan-form-input">{{detailInfo.briefIntroduction}}</span>
                        </a-form-model-item>
                        <a-form-model-item class="yuan-form-item" label="所在地区" prop="placeAreaCode" v-if="detailInfo.placeCity">
                            <span
                                class="yuan-form-input">{{detailInfo.placeCity.province + detailInfo.placeCity.city + detailInfo.placeCity.district}}</span>
                        </a-form-model-item>
                    </template>

                    <!----------- 企业 -------------->
                    <template v-else-if="detailInfo.userType==='企业/单位'">
                        <a-form-model-item class="yuan-form-item" label="企业/单位名称" prop="userName">
                            <span class="yuan-form-input">{{detailInfo.name}}</span>
                        </a-form-model-item>
                        <a-form-model-item class="yuan-form-item" label="成立日期">
                            <span class="yuan-form-input">{{detailInfo.dateOfEstablishment}}</span>
                        </a-form-model-item>
                        <div class="clear-both"></div>
                        <a-form-model-item class="yuan-form-item" label="信用代码" prop="userName">
                            <span class="yuan-form-input">{{detailInfo.creditCode}}</span>
                        </a-form-model-item>
                        <a-form-model-item class="yuan-form-item" label="法定代表人" prop="userName">
                            <span class="yuan-form-input">{{detailInfo.legalRepresentative}}</span>
                        </a-form-model-item>
                        <div class="clear-both"></div>
                        <a-form-model-item label="上传头像" class="yuan-form-row">
                            <div class="imagePreBox">
                                <img class="imagePreview" :src="detailInfo.headPortrait" alt=""
                                    @click="imgClick(detailInfo.headPortrait)">
                            </div>
                        </a-form-model-item>
                        <a-form-model-item label="营业执照" class="yuan-form-row">
                            <div class="imagePreBox">
                                <img class="imagePreview" :src="detailInfo.businessLicense" alt=""
                                    @click="imgClick(detailInfo.businessLicense)">
                            </div>
                        </a-form-model-item>
                        <a-form-model-item class="yuan-form-item" label="所在地区" prop="placeAreaCode" v-if="detailInfo.placeCity">
                            <span
                                class="yuan-form-input">{{detailInfo.placeCity.province + detailInfo.placeCity.city + detailInfo.placeCity.district}}</span>
                        </a-form-model-item>
                    </template>
                    <!----------- 专家 --------->
                    <template v-else-if="detailInfo.userType==='专家'">
                        <a-form-model-item class="yuan-form-item" label="姓名" prop="userName">
                            <span class="yuan-form-input">{{detailInfo.name}}</span>
                        </a-form-model-item>
                        <a-form-model-item class="yuan-form-item" label="性别">
                            <span class="yuan-form-input">{{detailInfo.gender}}</span>
                        </a-form-model-item>
                        <div class="clear-both"></div>
                        <a-form-model-item class="yuan-form-item" style="width:100%" label="所属学院">
                            <span class="yuan-form-input">{{detailInfo.placeCollege}}</span>
                        </a-form-model-item>
                        <div class="clear-both"></div>
                        <a-form-model-item class="yuan-form-item" label="邮箱">
                            <span class="yuan-form-input">{{detailInfo.email}}</span>
                        </a-form-model-item>
                        
                        <a-form-model-item class="yuan-form-row" label="领域">
                            <span class="yuan-form-input">{{detailInfo.territory.join(',')}}</span>
                        </a-form-model-item>
                        <div class="clear-both"></div>
                        <a-form-model-item label="上传头像" class="yuan-form-item">
                            <div class="imagePreBox">
                                <img class="imagePreview" :src="detailInfo.headPortrait" alt=""
                                    @click="imgClick(detailInfo.headPortrait)">
                            </div>
                        </a-form-model-item>

                        <div class="clear-both" style="margin-top:10px"></div>
                        <a-form-model-item class="yuan-form-row" label="简介">
                            <span class="yuan-form-input">{{detailInfo.briefIntroduction}}</span>
                        </a-form-model-item>
                        <a-form-model-item label="相关图片" class="yuan-form-row" v-if="detailInfo.correlationPicture">
                            <div class="imagePreBox" v-for="item in JSON.parse(detailInfo.correlationPicture)">
                                <img class="imagePreview" :src="item" alt="" @click="imgClick(item)">
                            </div>
                        </a-form-model-item>
                        <div class="clear-both" style="margin-top:10px"></div>
                        <a-form-model-item class="yuan-form-row" label="难点突破">
                            <span class="yuan-form-input">{{detailInfo.difficultyBreakThrough}}</span>
                        </a-form-model-item>
                        <div class="clear-both" style="margin-top:10px"></div>
                        <a-form-model-item class="yuan-form-row" label="核心技术">
                            <span class="yuan-form-input">{{detailInfo.coreTechnology}}</span>
                        </a-form-model-item>
                        <div class="clear-both" style="margin-top:10px"></div>
                        <a-form-model-item class="yuan-form-row" label="推广应用">
                            <span class="yuan-form-input">{{detailInfo.promotionUse}}</span>
                        </a-form-model-item>
                        <div class="clear-both" style="margin-top:10px"></div>
                        <a-form-model-item class="yuan-form-row" label="前期成果">
                            <span class="yuan-form-input">{{detailInfo.earlierStageAchievement}}</span>
                        </a-form-model-item>
                    </template>

                    <!----------- 专家团队 --------->
                    <template v-else-if="detailInfo.userType==='专家团队'">
                        <a-form-model-item class="yuan-form-item" label="团队名称" prop="userName">
                            <span class="yuan-form-input">{{detailInfo.name}}</span>
                        </a-form-model-item>
                        <a-form-model-item class="yuan-form-item" label="团队负责人">
                            <span class="yuan-form-input">{{detailInfo.teamPrincipal}}</span>
                        </a-form-model-item>
                        <a-form-model-item class="yuan-form-item" label="联系方式">
                            <span class="yuan-form-input">{{detailInfo.contactWay}}</span>
                        </a-form-model-item>
                        <div class="clear-both"></div>
                        <a-form-model-item class="yuan-form-item" label="所属学院">
                            <span class="yuan-form-input">{{detailInfo.placeCollege}}</span>
                        </a-form-model-item>
                        <a-form-model-item class="yuan-form-item" label="邮箱">
                            <span class="yuan-form-input">{{detailInfo.email}}</span>
                        </a-form-model-item>
                        <div class="clear-both"></div>
                        <a-form-model-item class="yuan-form-row" label="领域">
                            <span class="yuan-form-input">{{detailInfo.territory.join(',')}}</span>
                        </a-form-model-item>
                        <div class="clear-both" style="margin-top:10px"></div>
                        <a-form-model-item class="yuan-form-row" label="团队负责人简介">
                            <span class="yuan-form-input">{{detailInfo.briefIntroduction}}</span>
                        </a-form-model-item>
                        <a-form-model-item label="相关图片" class="yuan-form-row" v-if="detailInfo.correlationPicture">
                            <div class="imagePreBox" v-for="item in JSON.parse(detailInfo.correlationPicture)">
                                <img class="imagePreview" :src="item" alt="" @click="imgClick(item)">
                            </div>
                        </a-form-model-item>

                        <div class="clear-both" style="margin-top:10px"></div>
                        <a-form-model-item class="yuan-form-row" label="难点突破">
                            <span class="yuan-form-input">{{detailInfo.difficultyBreakThrough}}</span>
                        </a-form-model-item>
                        <div class="clear-both" style="margin-top:10px"></div>
                        <a-form-model-item class="yuan-form-row" label="核心技术">
                            <span class="yuan-form-input">{{detailInfo.coreTechnology}}</span>
                        </a-form-model-item>
                        <div class="clear-both" style="margin-top:10px"></div>
                        <a-form-model-item class="yuan-form-row" label="推广应用">
                            <span class="yuan-form-input">{{detailInfo.promotionUse}}</span>
                        </a-form-model-item>
                        <div class="clear-both" style="margin-top:10px"></div>
                        <a-form-model-item class="yuan-form-row" label="前期成果">
                            <span class="yuan-form-input">{{detailInfo.earlierStageAchievement}}</span>
                        </a-form-model-item>

                    </template>

                </div>
                <template v-if="detailInfo.auditTechnicalState!==null">
                    <div class="form-title">技术经纪人</div>
                    <div class="form-panel">

                        <BrokerVue :detailInfo="detailInfo" />

                    </div>
                </template>

            </a-form-model>
            <template slot="footer">
                <template v-if="!isShow">
                    <a-button @click="pass" type="primary" :loading="loading">
                        通过审核
                    </a-button>
                    <a-button @click="clickRefuse" type="danger">
                        驳回
                    </a-button>
                </template>

                <a-button @click="closeModal">
                    取消
                </a-button>
            </template>
        </a-modal>

        <a-modal width="600px" title="拒绝原因" :visible="refuseVisible" @ok="refuseOk" @cancel="refuseCancel" okText="确定"
            cancelText="取消">
            <a-spin tip="Loading..." :spinning="refuseLoading">
                <a-form-model layout="inline" class="yuan-form" :label-col="{ style: { width: '100px' } }"
                    :wrapper-col="{ style: { width: 'calc(100% - 120px)' } }">
                    <div class="form-panel">

                        <a-form-model-item label="拒绝原因" prop="number">
                            <a-input type="textarea" style="width: 500px;" :rows="5" placeholder="请输入拒绝原因" :maxLength="500" />
                        </a-form-model-item>
                    </div>
                </a-form-model>
            </a-spin>
        </a-modal>
        <PreviewImageVue :imgList="imageUrls" @close="previewVisible=false" :previewVisible="previewVisible" />
    </div>
</template>

<script lang="ts">
import { Vue, Component, Prop, Watch } from "vue-property-decorator";
import PreviewImageVue from "@/components/previewImage.vue";
import BrokerVue from "./components/broker.vue";
import api from "@/api/api";
@Component({
    name: "dom",
    components: { PreviewImageVue, BrokerVue },
})
export default class index extends Vue {
    @Prop({ default: false }) visible!: boolean;
    @Prop({ default: false }) isShow!: boolean;
    @Prop({ default: false }) isTechnical!: boolean;
    @Prop({ default: {} }) detailInfo!: any;

    @Watch("visible")
    visibleChange() {
        if (this.visible) {
            //console.info(this.isShow)
        }
    }
    loading = false;
    async mounted() {}
    closeModal() {
        this.$emit("closeModal");
    }
    async modalOk() {
        this.loading = true;
        try {
            // const res = await warningApi.planAdd(this.sureInfo);
            // this.$message.success(res.msg);
            this.closeModal();
            this.$emit("sureClose");
        } finally {
            this.loading = false;
        }
    }
    refuseLoading = false;
    refuseVisible = false;
    clickRefuse() {
        this.$confirm({
            title: "确定要驳回吗？",
            okText: "确定",
            cancelText: "取消",
            onOk: async () => {
                const data: any = {
                    id: this.detailInfo.id,
                    state: this.isTechnical ? 1 : 2,
                };

                if (this.isTechnical) {
                    data.auditTechnicalState = 2;
                } else if (this.detailInfo.hasTechnicalRepresentative === 0) {
                    data.auditTechnicalState = 2;
                }
                const res = await api.setUserAuth(data);
                this.$message.success(res.msg);
                this.closeModal();
                this.$emit("resetList");
            },
            onCancel: () => {
                console.log("Cancel");
            },
        });
        //this.refuseVisible = true;
    }
    refuseOk() {}
    refuseCancel() {
        this.refuseVisible = false;
    }
    pass() {
        this.$confirm({
            title: "确定要通过吗？",
            okText: "确定",
            cancelText: "取消",
            onOk: async () => {
                const data: any = {
                    id: this.detailInfo.id,
                    state: 1,
                };

                if (this.isTechnical) {
                    //技术经纪人审核
                    data.auditTechnicalState = 1;
                } else if (this.detailInfo.hasTechnicalRepresentative === 0) {
                    //人员注册审核
                    data.auditTechnicalState = 1;
                }

                const res = await api.setUserAuth(data);
                this.$message.success(res.msg);
                this.closeModal();
                this.$emit("resetList");
            },
            onCancel: () => {
                console.log("Cancel");
            },
        });
    }

    previewVisible = false;
    imageUrls: string[] = [];
    imgClick(url: string) {
        this.previewVisible = true;
        this.imageUrls = [url];
    }
    closeImg() {
        this.previewVisible = false;
    }
}
</script>

<style lang="scss">
.userauth-modal {
    .imagePreBox {
        width: 120px;
        height: 120px;
        border: solid 1px #eee;
        display: inline-flex;
        margin-right: 5px;
        align-items: center;
        justify-content: center;
    }
    .imagePreview {
        max-width: 100%;
        max-height: 100%;
    }
}
</style>
